﻿using UnityEngine;
using System.Collections.Generic;
using CommonFactory;
using System;

namespace CharacterSystem
{
    public class CharacterManager : ICharacterManager
    {
        HeroInfo HeroInfo;

        Dictionary<int, CharacterFactoryBase> id2CharacterFactory = new Dictionary<int, CharacterFactoryBase>();

        public void Init()
        {
            HeroInfo = Resources.Load<HeroInfo>("ScriptableObject/HeroInfo");
        }

        public ICommonProductData GetCharacterDataByID(int id)
        {
            for (int i = 0; i < HeroInfo.Data.Count; i++)
            {
               if(HeroInfo.Data[i].ID == id)
                {
                    return HeroInfo.Data[i];
                }
            }
            return null;
        }

        public CharacterBase CreateCharacter(int id)
        {
            throw new NotImplementedException();
        }

        public void RegisterCharacterFactory(int id, CharacterFactoryBase factory)
        {
            if (!id2CharacterFactory.ContainsKey(id))
            {
                id2CharacterFactory.Add(id, factory);
            }
            else
            {
                Debug.LogError("重复注册id: " + id);
            }
        }
    }
}